import java.net.*;
import java.io.*;

public class MultiServerThread extends Thread {    
	private Socket socket = null;
	String inputLine;
	PrintWriter out;

	public MultiServerThread(Socket socket) throws IOException {
		super("MultiSocketServer");
		this.socket = socket;

	}

	public void run() {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

			while ((inputLine = in.readLine()) != null) {
					String[] strings = split(inputLine);
					System.out.println(strings[0]);
					File f = new File(strings[0]);
					FileWriter fw = new FileWriter(f, true);
					BufferedWriter bw = new BufferedWriter(fw);
					for(int i = 1; i < strings.length; i++){
						bw.write(strings[i] +'\n');
						bw.flush();
					}
					bw.close();
				if (inputLine.equals(".Bye"))
					break;
			}
			//out.close();
			in.close();
			socket.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static String[] split(String phrase){
		String delims = "[/]";
		String[] tokens = phrase.split(delims);
		return tokens;
	}
}
